package com.loadburn.heron.template;

import com.loadburn.heron.template.TemplateSource;

import java.io.File;
import java.io.Serializable;
import java.net.URL;

/**
 * @author slacrey (scstlinfeng@yahoo.com)
 *         Date: 13-10-27
 */
public class TemplateSourceImpl implements TemplateSource, Serializable {

    private static final long serialVersionUID = -4379747882504369657L;
    private URL url;
    private File templateFile;
    private String templateDirectory;

    public TemplateSourceImpl(String templateDirectory, File templateFile) {
        this.templateFile = templateFile;
        this.templateDirectory = templateDirectory;
    }

    public TemplateSourceImpl(String templateDirectory, URL url) {
        this.url = url;
        this.templateDirectory = templateDirectory;
    }

    public TemplateSourceImpl(String templateDirectory) {
        this.templateDirectory = templateDirectory;
    }

    @Override
    public String getLocation() {
        if (templateFile == null) {
            return url.getPath();
        }
        return templateFile.getAbsolutePath();
    }

    public String getTemplateDirectory() {
        return templateDirectory;
    }

    public File getTemplateFile() {
        return templateFile;
    }
}
